<?php
include("funciones/setup.php");
conecta();

session_start();

if(isset($_SESSION['sesion_usuario']))
{
	$id=$_GET['id'];
	if(isset($id))
	{
		$sql="select * from proveedor where id_pro=".$id;
		$reg=mysql_query($sql);
		$datos=mysql_fetch_array($reg);
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>..:: Formulario de Proveedores ::..</title>
<link href="css/estilos_forms.css" rel="stylesheet" type="text/css" />
<link href="css/kendo.common.css" rel="stylesheet"/>
<link href="css/kendo.default.css" rel="stylesheet"/>

<script src="js/jquery-1.7.1.js" language="javascript" type="text/javascript"></script>
<script src="js/control_proveedores.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.core.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.numerictextbox.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.validator.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.combobox.js" language="javascript" type="text/javascript"></script>

<script src="js/jquery.Rut.js" type="text/javascript"></script>

<link rel="stylesheet" href="css/paginador_busqueda.css"/>
<script type="text/javascript" src="js/jquery.pagination.js"></script>
<link href="css/estilos_base.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><div id="credenciales">
      <table width="100%" border="0" cellspacing="3" cellpadding="0">
        <tr>
          <td width="42"><img src="imagenes/iconos/credenciales.png" width="42" height="28" /></td>
          <td class="fuente_normal">Bienvenido : <?php echo $_SESSION['sesion_usuario'];?></td>
        </tr>
        <tr>
          <td colspan="2"><table border="0" align="center" cellpadding="0" cellspacing="3">
            <tr>
              <td><a href="cerrar_sesion.php"><img src="imagenes/iconos/salir_session.png" width="22" height="23" border="0" /></a></td>
              <td class="fuente_normal"><a href="cerrar_sesion.php">Cerrar Sessión</a></td>
              <td class="fuente_normal">|</td>
              <td class="fuente_normal"><a href="panel_principal.php"><img src="imagenes/iconos/ico_panel_principal.png" width="22" height="23" border="0" /></a></td>
              <td class="fuente_normal"><a href="panel_principal.php">Panel Principal</a></td>
            </tr>
          </table></td>
        </tr>
      </table>
    </div></td>
    <td><div id="logotipo"><img src="imagenes/logo.png" width="200" height="82" /></div></td>
    <td><table border="0" align="right" cellpadding="0" cellspacing="5">
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><span class="fuente_login">La Serena, <?php echo fecha_hoy_mas_dia();?>&nbsp;</span></td>
      </tr>
    </table></td>
  </tr>
</table>
<br />
<div id="modulo">
  <form id="form1" name="form1" method="post" action="">
    <table border="0" align="center" cellpadding="0" cellspacing="10">
      <tr>
        <td class="fuente_formularios">R.U.T</td>
        <td colspan="3" class="fuente_formularios"><input name="frm_rut" type="text" class="k-textbox" id="frm_rut" value="<?php echo $datos['rut_pro'];?>" placeholder="Ingrese RUT" required/></td>
      </tr>
      <tr class="fuente_formularios">
        <td>Nombre Empresa</td>
        <td colspan="3"><input name="frm_nombre_prov" type="text" class="k-textbox" id="frm_nombre_prov" value="<?php echo $datos['nombre_pro'];?>" size="70" placeholder="Ingrese Nombre de la Empresa" required/></td>
      </tr>
      <tr>
        <td class="fuente_formularios">Razón Social</td>
        <td colspan="3" class="fuente_formularios"><input name="frm_razon_prov" type="text" class="k-textbox" id="frm_razon_prov" value="<?php echo $datos['razon_social'];?>" size="70" placeholder="Ingrese Razón Social" required="required"/></td>
      </tr>
      <tr>
        <td class="fuente_formularios">Giro</td>
        <td colspan="3" class="fuente_formularios"><input name="frm_giro_prov" type="text" class="k-textbox" id="frm_giro_prov" value="<?php echo $datos['giro'];?>" size="70" placeholder="Ingrese Giro de la Empresa" required="required"/></td>
      </tr>
      <tr>
        <td class="fuente_formularios">Direccion</td>
        <td colspan="3" class="fuente_formularios"><input name="frm_direccion_prov" type="text" class="k-textbox" id="frm_direccion_prov" value="<?php echo $datos['direccion_pro'];?>" size="70" placeholder="Ingrese la Dirección" required="required"/></td>
      </tr>
      <tr>
        <td class="fuente_formularios">Código Postal</td>
        <td class="fuente_formularios"><input name="frm_codigo_postal" type="text" class="k-textbox" id="frm_codigo_postal" value="<?php echo $datos['codigo'];?>" size="20" placeholder="Ingrese Codigo Postal" required="required"/></td>
        <td class="fuente_formularios">E-Mail</td>
        <td class="fuente_formularios"><input name="frm_email_prov" type="text" class="k-textbox" id="frm_email_prov" value="<?php echo $datos['mail_pro'];?>" size="20" placeholder="Ingrese E-Mail" required="required"/></td>
      </tr>
       <tr>
        <td class="fuente_formularios">Telefono</td>
        <td class="fuente_formularios"><input name="frm_telefono_prov" type="text" class="k-textbox" id="frm_telefono_prov" value="<?php echo $datos['telefono_pro'];?>" size="20" placeholder="Ingrese Telefono(s)" required="required"/></td>
        <td class="fuente_formularios">Fax</td>
        <td class="fuente_formularios"><input name="frm_fax_prov" type="text" class="k-textbox" id="frm_fax_prov" value="<?php echo $datos['fax'];?>" size="20" placeholder="Ingrese Fax" required="required"/></td>
      </tr>
      <tr>
        <td class="fuente_formularios">Estado</td>
        <td colspan="3" class="fuente_formularios"><select name="frm_estado" id="frm_estado" required>
          <option value="0">Seleccionar</option>
          <option value="1" <?php if($datos['estado']==1){?> selected="selected"<?php } ?>>Activo</option>
          <option value="2" <?php if($datos['estado']==2){?> selected="selected"<?php } ?>>Inactivo</option>
        </select></td>
      </tr>
      <tr>
        <td colspan="4"><center>
          <label for="oculto_id"></label>
          <input type="hidden" name="id_oculto" id="id_oculto" value="<?php echo $id;?>" />
          <?php
		    if(!isset($id))
			{
				?>
            <input type="button" name="btn_ingresar" id="btn_ingresar" value="Ingresar" class="k-button"/> 
            &nbsp;
            <?php
			}
			else
			{?>
            <input type="button" name="btn_modificar" id="btn_modificar" value="Modificar" class="k-button"/>
            &nbsp;
			<input type="button" name="btn_eliminar" id="btn_eliminar" value="Eliminar" class="k-button"/>
            &nbsp;
            <?php
			}
			?>
<input type="button" name="btn_ingresar4" id="btn_cancelar" value="Cancelar" class="k-button"/>
        </center></td>
      </tr>
    </table>
  </form>
</div>
<br />
<div id="paginador"></div>
<div id="Pagination"></div>
<script language="javascript">

$(document).ready(function(){
	
	$('#frm_rut').Rut(
	{
  		on_error: function(){ 
		     alert('Rut incorrecto'); 
			 $('#frm_rut').val("");
			 $('#frm_rut').focus();
	}
	});
	
	$("#btn_ingresar").click(function(){
		validar(1);
	});
	
	$("#btn_modificar").click(function(){
		validar(2);
	});
	
	$("#btn_eliminar").click(function(){
		eliminar();
	});
	
	$("#btn_cancelar").click(function(){
		cancelar();
	});
		
	$("#paginador").html(muestra_grilla());
});

</script>
</body>
</html>
<?php
}
else
{
	header("Location:index.php");
}
?>